<?php

class Sunny_ErrorHandled {

    public static $DONE = 0;
    public static $SERVER_ERROR = -1;
    public static $NO_DATA_RECORD = -2;
    public static $NO_API_OR_SIG = -3;
    public static $NOT_FOUND_APIKEY = -4;
    public static $INVAILD_PARAMS = -5;
    public static $INVAILD_METHOD = -6;
    public static $INVAILD_PAGE_OR_COUNT = -7;
    public static $INVAILD_TYPE_ON_SEARCH = -8;
    public static $NO_DATA_UPDATES = -9;
    public static $PAGE_NOT_FOUND = -10;
    public static $USER_FOUND = -11;
    public static $USER_NOT_FOUND = -12;
    public static $WRONG_PASS = -13;
    public static $EMAIL_FOUND = -14;

    public static function handleError($errorId) {
        if ($errorId == null)
            return null;
        switch ($errorId) {
             case self::$EMAIL_FOUND : {
                    return json_encode(array(
                                "errorId" => self::$EMAIL_FOUND,
                                "errorMessage" => "Email is used by other.",
                                "data" => null,
                            ));
                    break;
                }
            case self::$WRONG_PASS : {
                    return json_encode(array(
                                "errorId" => self::$WRONG_PASS,
                                "errorMessage" => "Password is incorrect.",
                                "data" => null,
                            ));
                    break;
                }
            case self::$USER_NOT_FOUND : {
                    return json_encode(array(
                                "errorId" => self::$USER_NOT_FOUND,
                                "errorMessage" => "User not found.",
                                "data" => null,
                            ));
                    break;
                }
            case self::$USER_FOUND : {
                    return json_encode(array(
                                "errorId" => self::$USER_FOUND,
                                "errorMessage" => "User has already exists.",
                                "data" => null,
                            ));
                    break;
                }
            case self::$SERVER_ERROR : {
                    return json_encode(array(
                                "errorId" => self::$SERVER_ERROR,
                                "errorMessage" => "Server error!",
                                "data" => null,
                            ));
                    break;
                }
            case self::$NO_DATA_RECORD : {
                    return json_encode(array(
                                "errorId" => self::$NO_DATA_RECORD,
                                "errorMessage" => "Database is empty",
                                "data" => null,
                            ));
                    break;
                }
            case self::$NO_API_OR_SIG : {
                    return json_encode(array(
                                "errorId" => self::$NO_API_OR_SIG,
                                "errorMessage" => "Miss param API or SIG",
                                "data" => null,
                            ));
                    break;
                }
            case self::$NOT_FOUND_APIKEY : {
                    return json_encode(array(
                                "errorId" => self::$NOT_FOUND_APIKEY,
                                "errorMessage" => "Your API key is not valid on our DB, please contact us. Phone 0916.916.295",
                                "data" => null,
                            ));
                    break;
                }
            case self::$INVAILD_PARAMS : {
                    return json_encode(array(
                                "errorId" => self::$INVAILD_PARAMS,
                                "errorMessage" => "Invalid Params when connecting to server",
                                "data" => null,
                            ));
                    break;
                }
            case self::$INVAILD_METHOD : {
                    return json_encode(array(
                                "errorId" => self::$INVAILD_PARAMS,
                                "errorMessage" => "Invalid method when connecting to server",
                                "data" => null,
                            ));
                    break;
                }
            case self::$INVAILD_PAGE_OR_COUNT : {
                    return json_encode(array(
                                "errorId" => self::$INVAILD_PAGE_OR_COUNT,
                                "errorMessage" => "Invalid page or count when connecting to server",
                                "data" => null,
                            ));
                    break;
                }
            case self::$INVAILD_TYPE_ON_SEARCH : {
                    return json_encode(array(
                                "errorId" => self::$INVAILD_TYPE_ON_SEARCH,
                                "errorMessage" => "Invalid type when connecting to server",
                                "data" => null,
                            ));
                    break;
                }
            case self::$NO_DATA_UPDATES : {
                    return json_encode(array(
                                "errorId" => self::$NO_DATA_UPDATES,
                                "errorMessage" => "No updates avaibles",
                                "data" => null,
                            ));
                    break;
                }
           case self::$PAGE_NOT_FOUND : {
                    return json_encode(array(
                                "errorId" => self::$PAGE_NOT_FOUND,
                                "errorMessage" => "Item not found.",
                                "data" => null,
                            ));
                    break;
                }
        }
    }

    public static function handleSuccess() {
        $arr['errorId'] = 0;
        $arr["errorMessage"] = "Done";
        return $arr;
    }

}

?>
